package com.lyc.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.lyc.dao.CountryInfoDAO;
import com.lyc.dao.imp.CountryInfoDAOImpl;
import com.lyc.dto.MedalSearch;
import com.lyc.service.MedalService;
import com.lyc.service.impl.MedalServiceImpl;

@WebServlet("/country.let")
public class CountryServlet extends HttpServlet {
	private CountryInfoDAO dao = new CountryInfoDAOImpl();
	private MedalService service = new MedalServiceImpl();

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		try {
			String countryCode = req.getParameter("countryCode");
			req.setAttribute("c", dao.selectById(countryCode));
			MedalSearch search = new MedalSearch();
			search.setRowMax(999);
			search.setCountryCode(countryCode);
			search.setMedalNum(1);
			req.setAttribute("list1", service.list(search));
			search.setMedalNum(2);
			req.setAttribute("list2", service.list(search));
			search.setMedalNum(3);
			req.setAttribute("list3", service.list(search));
			req.getRequestDispatcher("/country.jsp").forward(req, resp);
		} catch (Exception e) {
			throw new ServletException("获取国家奖牌错误", e);
		}
	}
}
